package com.aipodcast.webbackend;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;

import java.util.Collections;

/**
 * @author RedStar
 * @Date 2025/03/04
 * @Description
 */
public class CodeGenerator {
    public static void main(String[] args) {

        // 数据源配置
        String url = "jdbc:mysql://jhxblog.cn:33060/ai_podcast?serverTimezone=UTC&useSSL=false";
        String username = "root";
        String password = "newpassword";

        // 项目路径
        String projectPath = System.getProperty("user.dir");
        // Entity生成路径
        String entityPath = System.getProperty("user.dir") + "/src/main/java";
        // Mappers生成路径
        String MapperPath = projectPath + "/src/main/resources/mapper";
        // Service生成路径
        String ServiecPath = projectPath + "/service/src/main/java";
        // 生成表
        String[] tableAll = {"courses", "users"};
//        String[] table = {"resource"};

        // 生成所有表
        FastAutoGenerator.create(url, username, password)
                // 1️⃣ Entity 和 Mapper 放在 persistence 模块
                .globalConfig(builder -> builder.outputDir(entityPath))
                .packageConfig(builder -> builder.parent("com.aipodcast.webbackend")
                        .entity("entity")
                        .mapper("mapper")
                        .pathInfo(Collections.singletonMap(OutputFile.xml, MapperPath)))
                .strategyConfig(builder -> builder.addInclude(tableAll)
                        .entityBuilder().enableLombok())
                .execute();

        FastAutoGenerator.create(url, username, password)
                // 2️⃣ Service 层放在 service 模块
                .globalConfig(builder -> builder.outputDir(ServiecPath))
                .packageConfig(builder -> builder.parent("com.aipodcast.webbackend")
                        .service("service")
                        .serviceImpl("service.impl"))
                .strategyConfig(builder -> builder.addInclude(tableAll)
                        .controllerBuilder().disable()
                        .entityBuilder().disable()
                        .mapperBuilder().disable())
                .execute();

        // 生成个别表
//        FastAutoGenerator.create(url, username, password)
//                // 1️⃣ Entity 和 Mapper 放在 persistence 模块
//                .globalConfig(builder -> builder.outputDir(entityPath))
//                .packageConfig(builder -> builder.parent("com.xmnote")
//                        .entity("entity")
//                        .mapper("mapper")
//                        .pathInfo(Collections.singletonMap(OutputFile.xml, MapperPath)))
//                .strategyConfig(builder -> builder.addInclude(table)
//                        .entityBuilder().enableLombok().enableFileOverride()
//                        .controllerBuilder().disable()
////                        .mapperBuilder().disable()
////                        .serviceBuilder().disable()
//                )
//                .execute();
//
//        FastAutoGenerator.create(url, username, password)
//                // 2️⃣ Service 层放在 service 模块
//                .globalConfig(builder -> builder.outputDir(ServiecPath))
//                .packageConfig(builder -> builder.parent("com.xmnote")
//                        .service("service")
//                        .serviceImpl("service.impl"))
//                .strategyConfig(builder -> builder.addInclude(table)
//                        .controllerBuilder().disable()
//                        .entityBuilder().disable()
//                        .mapperBuilder().disable())
//                .execute();

    }
}
